home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr46 / vfwdk.zip / VFWSDK.ZIP / SAMPLES / BRAVADO / INITA.ASM < prev    next >
Assembly Source File  |  1993-01-31  |  9KB  |  308 lines

  1.         TITLE INITA.ASM
  2.         page 60,132
  3.  
  4. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5. ;
  6. ; INITA.ASM - Enable and Disable Interrupts
  7. ;
  8. ; (C) Copyright Microsoft Corp. 1992-1993.  All rights reserved.
  9. ;
  10. ; You have a royalty-free right to use, modify, reproduce and 
  11. ; distribute the Sample Files (and/or any modified version) in 
  12. ; any way you find useful, provided that you agree that 
  13. ; Microsoft has no warranty obligations or liability for any 
  14. ; Sample Application Files which are modified. 
  15. ;
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17.  
  18.         PMODE = 1
  19.  
  20.         .xlist
  21.         include cmacros.inc                   
  22.         include windows.inc
  23.         include mmsystem.inc
  24.         include vcap.inc
  25.         .list
  26.         .286
  27.  
  28.         ?PLM=1                          ; Pascal calling convention
  29.         ?WIN=0                          ; NO! Windows prolog/epilog code
  30.  
  31. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32. ;
  33. ;   extrn declarations
  34. ;
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  36.  
  37.         extrn   CT_ISR:far 
  38.     extrn     CT_IRQEnable:far 
  39.     extrn     CT_IRQDisable:far
  40.     extrn     CT_GetIRQUsed:far
  41.  
  42. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  43. ;
  44. ;   segmentation
  45. ;
  46. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  47.  
  48. IFNDEF SEGNAME
  49.         SEGNAME equ <_TEXT>
  50. ENDIF
  51.  
  52. createSeg %SEGNAME, CodeSeg, word, public, CODE
  53.  
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ;
  56. ;   data segment
  57. ;
  58. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  59.  
  60. sBegin Data
  61.  
  62.         externB gbInt,             -1
  63.         externW gwBaseReg,         -1
  64.  
  65.         globalD gdwOldISR,          0
  66.         globalB gfEnabled,          0
  67.  
  68. sEnd Data
  69.  
  70. sBegin DATA
  71.  
  72. sEnd DATA
  73.  
  74. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  75. ;
  76. ;   code segment
  77. ;
  78. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  79.  
  80. sBegin CodeSeg
  81.  
  82.         assumes cs, CodeSeg
  83.         assumes ds, Data
  84.  
  85.  
  86. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  87. ; IRQEnable    - This function enables the driver.  It will 
  88. ;          hook interrupts
  89. ;
  90. ; The return value is zero if the call is successful otherwise
  91. ; an error code is returned.
  92. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  93. ; FIX move to C
  94.  
  95. cProc IRQEnable <FAR, PASCAL, PUBLIC, WIN> <si, di>
  96.  
  97. cBegin
  98.         mov     al,[gfEnabled]          ; already enabled ?
  99.         or      al,al
  100.         jnz     IRQEnableExit
  101.  
  102.         cCall CT_GetIRQUsed             ; which interrupt to use?
  103.         mov     [gbInt], al
  104.  
  105.         mov     dx, seg CT_ISR
  106.         mov     ax, offset CT_ISR
  107.         mov     bl, [gbInt]
  108.  
  109.         cCall   InitSetInterruptVector, <bx,dx,ax>
  110.  
  111.         mov     [gdwOldISR].off,ax
  112.         mov     [gdwOldISR].sel,dx
  113.  
  114.     ; Enable interrupts
  115.         cCall CT_IRQEnable
  116.  
  117.         ; Enable interrrupts at the PIC
  118.         mov     bl, [gbInt]
  119.         cCall   InitSetIntMask, <bx, 0>
  120.  
  121.         inc     [gfEnabled]    ; mark as being enabled
  122.         xor     ax,ax          ; show success.
  123.  
  124. IRQEnableExit:
  125. cEnd
  126.  
  127. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  128. ; IRQDisable    This function disables the driver.  It disables the
  129. ;    the hardware, unhooks interrupts and frees any memory allocated.
  130. ;
  131. ; The return value is zero if the call is successful otherwise
  132. ; an error code is returned.
  133. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  134. cProc IRQDisable <FAR, PASCAL, PUBLIC, WIN> <si, di>
  135.  
  136. cBegin
  137.         mov     al,[gfEnabled]
  138.         or      al,al
  139.         jz      IRQDisableExit
  140.  
  141.     ; Disable interrupts on the frame grabber
  142.         cCall CT_IRQDisable
  143.  
  144.         ; disable interrupts at the PIC
  145.         mov     bl, [gbInt]
  146.         cCall   InitSetIntMask, <bx, 1>
  147.  
  148.         mov     ax,[gdwOldISR].off
  149.         mov     dx,[gdwOldISR].sel
  150.         mov     bl,[gbInt]
  151.  
  152.         cCall   InitSetInterruptVector, <bx,dx,ax>
  153.  
  154.         dec     [gfEnabled]
  155.  
  156. IRQDisableExit:
  157.          
  158.         xor     ax,ax
  159. cEnd
  160.  
  161. ;---------------------------------------------------------------------------;
  162. ;
  163. ;   BOOL NEAR PASCAL InitSetIntMask( bIRQ, bMask )
  164. ;
  165. ;   DESCRIPTION:
  166. ;       This function sets or unsets interupt vector mask.
  167. ;
  168. ;   ENTRY:
  169. ;       ParmB   bIRQ        :   The IRQ (0 - 15) to mask/unmask
  170. ;       ParmB   bMask       :   The mask
  171. ;
  172. ;   EXIT:
  173. ;       AX    :   The return value is the previous interrupt mask.
  174. ;
  175. ;   HISTORY:
  176. ;
  177. ;---------------------------------------------------------------------------;
  178.  
  179.         assumes ds, Data
  180.         assumes es, nothing
  181.  
  182. cProc InitSetIntMask <NEAR, PUBLIC> <>
  183.         ParmB   bIRQ
  184.         ParmB   bMask
  185. cBegin
  186. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  187. ;   see if we need to talk to the slave or master PIC
  188. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  189.         mov     cl, bIRQ
  190.         mov     dx, PIC_IMR_MASTER
  191.         cmp     cl, 8
  192.         jb      SetIntMask_Master
  193.         and     cl, 07h
  194.         mov     dx, PIC_IMR_SLAVE
  195. SetIntMask_Master:
  196.  
  197. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  198. ;   compute the interupt mask.
  199. ;       DX = slave or master mask register
  200. ;       CL = 0-7 bit to set/clear
  201. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  202.         mov     ch, 1                   ; CH = 1
  203.         shl     ch, cl                  ; CH = int mask
  204.  
  205.         mov     cl, bMask               ; get mask
  206.         or      cl, cl
  207.         jz      SetIntMask_UnMask
  208.         mov     cl,ch
  209. SetIntMask_UnMask:
  210.  
  211. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  212. ;   CH  = PIC mask         (1 << (bInt&7))
  213. ;   CL  = wanted mask      bMask ? ch : 0
  214. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  215.         not     ch                      ; we need inverse of mask
  216.  
  217.         EnterCrit                       ; !!! Trashes BX !!!
  218.         in      al, dx                  ; grab current mask
  219.         mov     ah, al                  ; save it
  220.         and     al, ch                  ; clear bit
  221.         or      al, cl                  ; clear or set based on bMask
  222.         cmp     al, ah                  ; don't set the same state again!
  223.         je      SetIntMask_Same
  224.         out     dx, al                  ; enable/disable ints...
  225. SetIntMask_Same:
  226.         LeaveCrit                       ; !!! Trashes BX !!!
  227.  
  228. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  229. ;   we have set/cleared the PIC, now return the old state.
  230. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  231.         not     ch                      ; return previous mask state
  232.         mov     al, ah
  233.         and     al, ch
  234.         xor     ah, ah
  235. cEnd
  236.  
  237. ;---------------------------------------------------------------------------;
  238. ;
  239. ;   LPFUNC NEAR PASCAL InitSetInterruptVector( bIRQ, lpNewISR )
  240. ;
  241. ;   DESCRIPTION:
  242. ;       This function takes the IRQ and sets the appropriate interrupt
  243. ;       vector; and returns the pointer to the previous handler of the 
  244. ;       IRQ.
  245. ;
  246. ;   ENTRY:
  247. ;       ParmB   bIRQ        :   The IRQ (0 - 15) to install handler for.
  248. ;       ParmD   lpNewISR    :   The handler
  249. ;
  250. ;   EXIT:
  251. ;       DX:AX   :   The return value is the previous interrupt handler.
  252. ;
  253. ;   HISTORY:
  254. ;
  255. ;---------------------------------------------------------------------------;
  256.  
  257.         assumes ds, Data
  258.         assumes es, nothing
  259.  
  260. cProc InitSetInterruptVector <NEAR, PUBLIC> <>
  261.         ParmB   bIRQ
  262.         ParmD   lpNewISR
  263. cBegin
  264.  
  265. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  266. ;   convert IRQ to interrupt vector...
  267. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  268.  
  269.         mov     al, bIRQ
  270.         mov     ah, 08h
  271.         cmp     al, ah                  ; Q: slave or master IRQ?
  272.         jl      isv_Continue
  273.  
  274.         mov     ah, (70h - 08h)         ;   slave
  275.  
  276. isv_Continue:
  277.  
  278.         add     al, ah                  ; AL = interrupt vector
  279.  
  280. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  281. ;   get old interrupt vector (AL == interrupt vector)
  282. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  283.  
  284.         mov     ah, 35h
  285.         int     21h                     ; get the old vector in es:bx
  286.  
  287.         push    es                      ; save for a bit
  288.         push    bx
  289.  
  290. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  291. ;   set new interrupt vector (AL == interrupt vector)
  292. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  293.  
  294.         mov     ah, 25h
  295.         push    ds
  296.         lds     dx, lpNewISR
  297.         assumes ds, nothing
  298.         int     21h                     ; set the new vector
  299.         pop     ds
  300.  
  301.         pop     ax                      ; restore old ISR for return value
  302.         pop     dx                      ; ... DX:AX is old handler
  303. cEnd
  304.  
  305. sEnd CodeSeg
  306.  
  307.         end
  308.